package com.atguigu.bigdata.scala.mytest.chapter07

object Test_ScalaMatchObject {
  def main(args: Array[String]): Unit = {
    val li: Student = new Student("li",19)//伴生类创建对象
    val result:String = li match {
      //半生对象的apply方法创建对象
      case Student("li", 20) => "li20"
      case Student("li", 19) => "li19"
    }
    println(result)

    //将该List(1,2,3,4,5,6,"test")中的Int类型的元素加一，String类型拼接hello
    val list : List[Any] = List(1,2,3,4,5,6,"test")
    val list1: List[Any] = list.collect {
      case a: Int => a + 1
      case b: String => b + "hello"
    }
    println(list1)//List(2, 3, 4, 5, 6, 7, testhello)

  }
}

//样例类-->匹配模式
case class Student(var name:String,age:Int){

}
